package ink.lovejinhu.swardToOffer;

public class Offer_058_I {
    /**
     * 翻转单词顺序
     *
     * @param s
     * @return
     */
    public String reverseWords(String s) {
        s = s.trim();
        String[] s1 = s.split(" ");
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = s1.length - 1; i >= 1; i--) {
            if (!s1[i].equals("")) {
                stringBuilder.append(s1[i]);
                stringBuilder.append(" ");
            }
        }
        if (!s1[0].equals("")) {
            stringBuilder.append(s1[0]);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        String s = new String("  ");
        System.out.println(s.charAt(0) == ' ');
        String temp = "a good   example";
        // temp = temp.trim();
        String[] s1 = temp.split(" ");
        System.out.println(s1.length);
        for (int i = 0; i < s1.length; i++) {
            System.out.println(s1[i]);

        }
        String res = "aaaaa11111";
        String[] as = res.split("a");
        System.out.println(as.length);
        for (int i = 0; i < as.length; i++) {
            System.out.println(as[i]);

        }
    }
}
